#import "SMRShadowRatingCell.h"
#import "SMRShadowRatingView.h"


#pragma mark Constants


#pragma mark -
#pragma mark Class Globals


#pragma mark -
@interface SMRShadowRatingCell (SMRShadowRatingCellPrivateMethods)
-(void)initializeCell_;
-(void)updateRatingColor_;
-(SMRShadowRatingView *)shadowControl_;
@end


#pragma mark -
@implementation SMRShadowRatingCell

@synthesize editing;
@synthesize normalColor;
@synthesize highlightedColor;
@synthesize editingColor;
@synthesize overlayInnerRect;

-(id)initWithLevelIndicatorStyle:(NSLevelIndicatorStyle)levelIndicatorStyle {
	if (!(self = [super initWithLevelIndicatorStyle:levelIndicatorStyle]))
		return nil;
	[self initializeCell_];
	return self;
}

-(id)initWithCoder:(NSCoder *)aDecoder {
	if (!(self = [super initWithCoder:aDecoder]))
		return nil;
	[self initializeCell_];
	return self;
}

-(void)initializeCell_ {
	[self setNormalColor:[NSColor colorWithCalibratedWhite:0.0f alpha:1.0f]];
	[self setHighlightedColor:[NSColor colorWithCalibratedWhite:0.0f alpha:1.0f]];
	[self setEditingColor:[NSColor colorWithCalibratedWhite:0.0f alpha:1.0f]];
}


#pragma mark -
#pragma mark Accessors

-(void)setEditing:(BOOL)shouldEdit {
	editing = shouldEdit;
	[self updateRatingColor_];
}


#pragma mark -
#pragma mark Drawing

-(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
	if ([self editing]) {
		NSRect overlayRect = [self overlayInnerRect];
		[[NSColor whiteColor] setFill];
		[NSBezierPath fillRect:overlayRect];
	}
	[super drawWithFrame:cellFrame inView:controlView];
}


#pragma mark -
#pragma mark Overrides

-(void)setHighlighted:(BOOL)shouldHighlight {
	[super setHighlighted:shouldHighlight];
	[self updateRatingColor_];
}


#pragma mark -
#pragma mark Private

-(void)updateRatingColor_ {
	NSColor *notEditingColor = [self isHighlighted] ? [self highlightedColor] : [self normalColor];
	[self setRatingColor:[self editing] ? [self editingColor] : notEditingColor];
}

-(SMRShadowRatingView *)shadowControl_ {
	return (SMRShadowRatingView *)[self controlView];
}

@end
